// /!*=========================表单验证==============================*!/
//验证用户名
document.querySelector(".username").onblur = checkUsername;
function  checkUsername(){
    //（1）获得用户名
    var username = document.querySelector(".username").value;
    console.log("用户名：" + username);

    //(2)用户名是否合格
    if(username == "" || username == null){// 是否为空
        //(3)消息提示
        document.querySelector(".username-msg").innerText = "用户名不能为空";
        return false;
    }else if( !/^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$/.test(username) ){ //
        document.querySelector(".username-msg").innerText = "昵称只含有汉字、数字、字母、下划线不能以下划线开头和结尾";
        return false;
    }else{
        document.querySelector(".username-msg").innerText = "";
        return true;
    }

}
//验证手机号码
document.querySelector(".usertel").onblur = checkUserTel;
function  checkUserTel(){
    var userTel = document.querySelector(".userTel").value;
    if(userTel == "" || userTel == null){// 是否为空
        //(3)消息提示
        document.querySelector(".userTel-msg").innerText = "手机号码不能为空";
        return false;
    }else if( !/^(0|86|17951)?1[0-9]{10}$/.test(userTel) ){
        document.querySelector(".userTel-msg").innerText = "不是有效的手机号码";
        return false;
    }else{
        document.querySelector(".userTel-msg").innerText = "";
        return true;
    }
}
//验证密码
document.querySelector(".password").onblur = checkPassword;
function  checkPassword(){
    var password = document.querySelector(".password").value;
    if(password == "" || password == null){// 是否为空
        //(3)消息提示
        document.querySelector(".password-msg").innerText = "密码不能为空";
        return false;
    }else if( !/^[a-zA-Z0-9]\w{5,19}$/.test(password) ){
        document.querySelector(".password-msg").innerText = "密码只能由6~20字母数字或下划线";
        return false;
    }else{
        document.querySelector(".password-msg").innerText = "";
        return true;
    }
}

//密码确认
function validate() {
    var password1 = document.getElementById("password1").value;
    var password2 = document.getElementById("password2").value;
    if(password1 == password2) {
    document.getElementById("tishi").innerHTML="<font color='green'>两次密码相同</font>";
    // document.getElementById("submit").disabled = false;
    return true;
    }
    else {
    document.getElementById("tishi").innerHTML="<font color='red'>两次密码不相同</font>";
    // document.getElementById("submit").disabled = true;
    return false;
    }
}
// 提交表单，验证
document.querySelector(".moco-btn").onclick= function (){

    if(checkUsername() && checkUserTel() && checkPassword() && validate()){

        $("#signup-from").button();
    };

}
